<!DOCTYPE html>
<html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vue Template</title>
</head>
<body>
    <template id="cpn">
        <div>
            我是子组件
        </div>
    </template>
    <div id="app">
        <cpn></cpn>
        <cpn></cpn>
        <cpn ref="aaa"></cpn>
        <button @click="btnClick">按钮</button>
    </div>
<script src="../js/vue.js"></script>
<script>
    const app = new Vue({
        el: '#app',
        data: {
            message: 'hello Vue!'
        },
        methods: {
            btnClick(){
                // console.log(this.$children)
                // this.$children[0].showMessage()
                this.$refs.aaa.showMessage()
                
            }
        },
        components:{
            cpn: {
                template: '#cpn',
                methods: {
                    showMessage(){
                        console.log('showMessage');
                    }
                },
            }
        }
    })
</script>
</body>
</html>